<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ include file="/jsp/common/common.jsp" %>
</head>
<body>

<div class="tableMainWarp">
  <div class="top-div"><em></em><span>&nbsp;>&nbsp;定时调度&nbsp;>&nbsp;任务列表</span></div>
  <div>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="search-table">
      <tr>
      	<td>任务名称：</td>
      	<td><input class="table-input" id="jobName" name="jobName" value=""/></td>
      	<td>任务组名：</td>
      	<td><input class="table-input" id="jobGroup" name="jobGroup" value=""/></td>
      	<td colspan="4" align="right">
      	    <button class="btn-table" id="addJobButton">添加</button>
      		<button class="btn-table" id="deleteJobButton">删除</button>
      		<button class="btn-table" id="pauseJobButton">暂停</button>
      		<button class="btn-table" id="resumeJobButton">恢复</button>
	        <button class="btn-table" id="searchButton">查询</button>
        </td>
      </tr>	
      
    </table>
  </div>
  <div class="tablelist">
    <div class="tabcon" id="middleCon"  style="overflow: auto;"></div>
    <div id="paginationDiv"  class="page clearfix"></div>
  </div>
</div>


<script type="text/javascript">

$(document).ready(function(){
	
	var bodyHt=document.documentElement.clientHeight;
	var tableDivHeight = bodyHt-167;	
	$('#middleCon').height(tableDivHeight);
	
	getPageData();

	initTable();
	
	blindPageElement();
	
});

function blindPageElement(){

	//绑定查询按钮
	$('#searchButton').on('click',function(){
		
		$('#middleCon').tablegrid('reload',{
			jobName : $('#jobName').val(),
			jobGroup : $('#jobGroup').val()
		});
	});
	
	//绑定添加按钮
	$('#addJobButton').on('click',function(){
		
		openEditPage('添加任务', '', '')
		
	});
	
}

function openEditPage(title,jobName,jobGroup){
	
	var url = '<%=basePath%>/webframework/scheduler/showEditJob.do?';
	url = url + 'jobName='+jobName;
	url = url + '&jobGroup='+jobGroup;
	
	var editPage = new $.layer({
		type:'iframe',
		title: title,
		width:1324,
		height:528,
		content:url,
		buttonArray:[
		   {
			   name: '取消',
			   callback:function(){
				   editPage.close();
			   }
		   }
		]
	});
	
	editPage.show();
	
}

function initTable(){
 	
	var url = "<%=basePath%>/webframework/scheduler/getQuartzJobData.do?";
	
	$('#middleCon').tablegrid({
		url: url,
		columns:[	
		         	{field:'jobName',ischeckbox:true,align:'center',width:4},
		   	        {field:'jobName',title:'任务名称',width:15},
		   	        {field:'jobGroup',title:'任务组名',width:15},
		   	     	{field:'description',title:'任务描述',width:20},
		   	     	{field:'jobClassName',title:'执行任务类',width:36},
		   	     	{field:'jobName',title:'操作',width:10,formatter:operateFormatterFunction}
			    ],
	    isPagination:true,
	    resizeColumns : true,
	    pageConifg:{
	    	pageId : 'paginationDiv'
	    },
	    tableClass : 'table-form'
	});
}


function getPageData(){
	
	
}

function operateFormatterFunction(value, rowdata, index){
	
	var operate0 = $('<a href="javascript:;"></a>').on('click',function(){
		excuteNow(rowdata.jobName,rowdata.jobGroup);
	}).append('立即执行');
	
	return operate0;
	
}

function excuteNow(jobName,jobGroup){
	
 	var url = '<%=basePath%>/webframework/scheduler/excuteNow.do';
 	url = url + '?jobName='+jobName;
 	url = url + '&jobGroup='+jobGroup;
 	
	$.ajax({  
        url:url,  
        type:'post',  
        dataType:'json',  
        success:function(data,textStatus,jqXHR){
        	showAlert(jobName+'|'+jobGroup+' 执行成功');
        },  
        error:function(XMLHttpRequest,textStatus,errorThrown){  
        }                     
    });
}



</script>
</body>
</html>